package a.a.a.web;

import java.util.List;
import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import a.a.a.filesystem.GroupRepository;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {

	// private static final Logger logger =
	// LoggerFactory.getLogger(HomeController.class);

	@Autowired
	private GroupRepository groupRepository;

	public GroupRepository getGroupRepository() {
		return groupRepository;
	}

	public void setGroupRepository(GroupRepository groupRepository) {
		this.groupRepository = groupRepository;
	}

	@RequestMapping(value = "accessdenied")
	public String accessDenied(Locale locale, Model model) {
		return "denial/accessDenied";
	}

	@RequestMapping(value = { "home" })
	public String home(Locale locale, Model model) {
		List<String> years = groupRepository.getGroups();
		model.addAttribute("allGroups", years);
		return "pages/home";
	}

	// value = { ... , "*" }
	@RequestMapping(value = { "", "/", "login" }, method = RequestMethod.GET)
	public String login(Locale locale, Model model) {
		return "pages/login";
	}

}
